package io.github.uicdb.et.item.curios;

import com.google.common.collect.Multimap;
import io.github.uicdb.et.ModAttachments;
import io.github.uicdb.et.ModElements;
import net.minecraft.ChatFormatting;
import net.minecraft.core.Holder;
import net.minecraft.network.chat.Component;
import net.minecraft.resources.ResourceLocation;
import net.minecraft.world.entity.ai.attributes.Attribute;
import net.minecraft.world.entity.ai.attributes.AttributeModifier;
import net.minecraft.world.entity.ai.attributes.Attributes;
import net.minecraft.world.entity.player.Player;
import net.minecraft.world.item.ItemStack;
import top.theillusivec4.curios.api.SlotContext;

import java.util.List;

public class MapleSorrowItem extends CurioItem {
    public MapleSorrowItem(Properties properties) {
        super(properties, 0);
    }

    @Override
    public void appendDefaultAttribute(Multimap<Holder<Attribute>, AttributeModifier> map, SlotContext slotContext, ResourceLocation id, ItemStack stack) {
        map.put(Attributes.ATTACK_DAMAGE, getSlotModifier(0, slotContext, 0.4, AttributeModifier.Operation.ADD_MULTIPLIED_TOTAL));
    }

    @Override
    public void addAdditionTooltip(List<Component> tooltips, ItemStack stack) {
        tooltips.add(translate("maple_sorrow.0").withStyle(ChatFormatting.LIGHT_PURPLE));
        tooltips.add(translate("maple_sorrow.1").withStyle(ChatFormatting.RED));
    }

    @Override
    public void curioTick(SlotContext slotContext, ItemStack stack) {
        if (slotContext.entity() instanceof Player player && player.getRandom().nextFloat() < 0.2f) {
            var data = player.getData(ModAttachments.LAST_ATTACK_TIME.get());
            if (data > 1200) {
                player.hurt(player.damageSources().magic(), 0.5f + ((float) data - 1200f) / 100f);
                //一分钟不打人，20%几率每tick掉0.5生命,每5s伤害基础增加1点
            }
        }
    }
}
